package com.devunion.bogdan.view.dialogs;

import com.devunion.bogdan.view.util.i18n;
import com.devunion.bogdan.view.util.DialogHelper;
import com.devunion.bogdan.view.util.ComponentFactory;
import com.devunion.bogdan.model.project.User;
import com.devunion.bogdan.model.project.UserRole;
import com.devunion.bogdan.model.project.Ontology;
import com.devunion.bogdan.model.UserManager;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * @author Victar Liaskovich
 */
public class OntologyPropertyDialog extends JDialog {
    private String property;
    private String values;
    private JTextField jTextFieldProperty;
    private JTextField jTextFieldValues;

    public OntologyPropertyDialog(Frame owner) {
        super(owner, i18n.getString("OntologyDialog.Title"), true);

        initComponents();
    }

    private void initComponents() {
        getContentPane().setLayout(new GridBagLayout());

        jTextFieldProperty = new JTextField(10);
        jTextFieldValues = new JTextField(10);

        JLabel jLabelProperty = new JLabel(i18n.getString("OntologyDialog.Property"));
        jLabelProperty.setLabelFor(jTextFieldProperty);

        DialogHelper.placeComponent(getContentPane(), jLabelProperty,
                0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
                10, 10, 10, 0);

        if (property != null) {
            jTextFieldProperty.setText(property);
        }
        DialogHelper.placeComponent(getContentPane(), jTextFieldProperty,
                1, 0, 1, 1, 0.1, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
                10, 0, 10, 0);

        JLabel jLabelValues = new JLabel(i18n.getString("OntologyDialog.Values"));
        jLabelValues.setLabelFor(jTextFieldValues);

        DialogHelper.placeComponent(getContentPane(), jLabelValues,
                0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
                10, 10, 10, 0);

        if (values != null) {
            jTextFieldValues.setText(values);
        }

        DialogHelper.placeComponent(getContentPane(), jTextFieldValues,
                1, 1, 1, 1, 0.1, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.HORIZONTAL,
                10, 0, 10, 0);

        DialogHelper.placeComponent(getContentPane(), new JLabel("Please, spearate ontology values with comma (,)"),
                0, 2, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
                10, 10, 10, 0);

        DialogHelper.placeComponent(getContentPane(), ComponentFactory.getHR(),
                0, 3, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
                10, 10, 10, 0);

        Component OkCancelPanel = ComponentFactory.createPanelButtonOkCancel(this, new ComponentFactory.ActionHandler() {
            public void execute() {
                property = jTextFieldProperty.getText();
                values = jTextFieldValues.getText();
                setVisible(false);
            }
        }, new ComponentFactory.ActionHandler() {
            public void execute() {
                property = null;
                values = null;
                setVisible(false);
            }
        }, new ComponentFactory.ActionValidator() {
            public boolean validate() {
                return true;
            }
        });

        DialogHelper.placeComponent(getContentPane(), OkCancelPanel,
                0, 3, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.HORIZONTAL,
                10, 10, 10, 10);
    }

    public String getProperty() {
        return property;
    }

    public String getValues() {
        return values;
    }

    public void setProperty(String property) {
        this.property = property;
        jTextFieldProperty.setText(property);
    }

    public void setValues(String values) {
        this.values = values;
        jTextFieldValues.setText(values);
    }
}